package com.sjp.demo.dubbo.api.utils;

import com.sjp.demo.dubbo.api.enums.StatusCode;
import com.sjp.demo.dubbo.api.response.BaseResponse;

public class ResponseUtils {

    public static <T> BaseResponse<T> success(T data) {
        BaseResponse<T> response = new BaseResponse<>();
        response.setData(data);
        response.setCode(StatusCode.SUCCESS.getCode());
        response.setMsg("操作成功");
        return response;
    }

    public static BaseResponse success() {
        BaseResponse response = new BaseResponse();
        response.setCode(StatusCode.SUCCESS.getCode());
        response.setMsg("操作成功");
        return response;
    }

    public static BaseResponse error(String msg) {
        BaseResponse response = new BaseResponse();
        response.setCode(StatusCode.ERROR.getCode());
        response.setMsg(msg);
        return response;
    }

    public static BaseResponse create(StatusCode statusCode) {
        BaseResponse response = new BaseResponse();
        response.setCode(statusCode.getCode());
        response.setMsg(statusCode.getMsg());
        return response;
    }

}
